package com.JobFind.logic.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


import com.JobFind.DAO.ICompanyDAO;
import com.JobFind.logic.ICompanyLogic;
import com.JobFind.model.TbCompany;

@Component
public class CompanyLogic implements ICompanyLogic {

	private ICompanyDAO companyDAO;
    private ICompanyLogic companyLogic;
	public ICompanyDAO getCompanyrDAO() {
		return companyDAO;
	}

	public ICompanyDAO getCompanyDAO() {
		return companyDAO;
	}

	@Resource
	public void setCompanyDAO(ICompanyDAO companyDAO) {
		this.companyDAO = companyDAO;
	}

	public ICompanyLogic getCompanyLogic() {
		return companyLogic;
	}

	@Resource
	public void setCompanyLogic(ICompanyLogic companyLogic) {
		this.companyLogic = companyLogic;
	}




	@Override
	@Transactional
	public Integer loginCheck(String companyLoginName, String companyPwd) throws Exception {
		Integer result = 0;
		try {
			System.out.println("companyLoginName"+companyLoginName+"companyPwd"+companyPwd);
			List<TbCompany> companylist = companyDAO.loginCheck(companyLoginName);
			if (companylist == null) {
				result = 0;
			} else if (companylist.size() == 0) {
				result = 0;
			} else {
				TbCompany companybean = (TbCompany) companylist.get(0);
				if (!companyPwd.equals(companybean.getCompanyPwd())) {
					result = -1;
				} else {
					System.out.println(companybean.getCompanyId());
					return companybean.getCompanyId();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			result = -2;
		}
		return result;
	}
}
